/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package exemple;


import java.util.List;
 
 
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;

 
import util.HibernateUtil;
 
public class ProcessusBDAO extends HibernateUtil {
 
    public void add(List<ProcessusB> listProcess,HistoricSystem historicSystem) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        
        session.beginTransaction();
        
        for (ProcessusB p : listProcess) {
            p.setHistoricSystem(historicSystem);
            session.saveOrUpdate(p);
        }
        session.getTransaction().commit();
    }  

    public List<ProcessusB> listProcess(int id_historic) {
        Session session = HibernateUtil.getSessionFactory().getCurrentSession();
        session.beginTransaction();
        List<ProcessusB> listProcess = null;
        try {
            Query query = session.createQuery("from ProcessusB where id_historic in (:id_histo)");
            query.setParameter("id_histo", id_historic);
            listProcess = (List<ProcessusB>)query.list();
        } catch (HibernateException e) {
            e.printStackTrace();
            session.getTransaction().rollback();
        }
        session.getTransaction().commit();
        return listProcess;
    }
}